home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Bombardier_PC / DATACH.CST / 00079_Script_79 < prev    next >
Text File  |  1999-03-07  |  11KB  |  306 lines

  1. -- database routines
  2. --
  3. -- chris howell
  4. -- 
  5.  
  6. global DBRECORD
  7. global DBHANDLE
  8. global qdHandle
  9. global rsHandle
  10.  
  11. --
  12. --   Bar Chart routines - for hourly operating costs
  13.  
  14. on drawmainbars
  15.   global OBmisc, OBapu, OBengine, OBair, OBfuel, OBtotal
  16.   global OBCmisc, OBCapu, OBCengine, OBCair, OBCfuel, OBCtotal
  17.   --  set totalmain =   OBmisc + OBapu + OBengine + OBair + OBfuel
  18.   --  set totalcomp =   OBCmisc + OBCapu + OBCengine + OBCair + OBCfuel
  19.   set totalmain =   OBtotal
  20.   set totalcomp =   OBctotal
  21.   if totalcomp > totalmain then
  22.     set totalmain = totalcomp
  23.   end if
  24.   -- get framing
  25.   --  set chartrect_top = the top of sprite 22
  26.   --  set chartrect_bottom = the bottom of sprite 22
  27.   --  set c_left = the left of sprite 22
  28.   --  --  set c_right = the right of sprite 22
  29.   --  set c_right = c_left + 75
  30.   set chartrect_top = 230
  31.   set chartrect_bottom = 413
  32.   set c_left = 304
  33.   --  set c_right = the right of sprite 22
  34.   set c_right =  c_left + 75
  35.   
  36.   set current_bottom = chartrect_bottom 
  37.   -- calculate relative bar sizes and positions
  38.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  39. * OBfuel)
  40.   set xtop = chartrect_bottom - xxtop
  41.   set the rect of sprite 10 = rect(c_left,xtop,c_right,current_bottom)
  42.   set current_bottom = xtop
  43.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  44. * OBair)
  45.   set xtop = current_bottom - xxtop
  46.   set the rect of sprite 11 = rect(c_left,xtop,c_right,current_bottom)
  47.   set current_bottom = xtop
  48.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  49. * OBengine)
  50.   set xtop = current_bottom - xxtop
  51.   set the rect of sprite 12 = rect(c_left,xtop,c_right,current_bottom)
  52.   set current_bottom = xtop
  53.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  54. * OBapu)
  55.   set xtop = current_bottom - xxtop
  56.   set the rect of sprite 13 = rect(c_left,xtop,c_right,current_bottom)
  57.   set current_bottom = xtop
  58.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  59. * OBmisc)
  60.   set xtop = current_bottom - xxtop
  61.   set the rect of sprite 14 = rect(c_left,xtop,c_right,current_bottom)
  62.   set current_bottom = xtop
  63.   updatestage
  64. end
  65.  
  66. on drawcompbars
  67.   global OBmisc, OBapu, OBengine, OBair, OBfuel
  68.   global OBCmisc, OBCapu, OBCengine, OBCair, OBCfuel, OBtotal, OBCtotal
  69.   repeat with i = 34 to 38.
  70.     puppetsprite i, false
  71.     set the visible of sprite i = true
  72.   end repeat
  73.   updatestage
  74.   set totalmain =   OBtotal
  75.   set totalcomp =   OBctotal
  76.   if totalcomp > totalmain then
  77.     set totalmain = totalcomp
  78.   end if
  79.   -- get framing
  80.   
  81.   set chartrect_top = 230
  82.   set chartrect_bottom = 413
  83.   -- set c_left = the left of sprite 22
  84.   set c_right = 495
  85.   set c_left = 495 - 75
  86.   
  87.   --  set chartrect_top = the top of sprite 22
  88.   --  set chartrect_bottom = the bottom of sprite 22
  89.   --  -- set c_left = the left of sprite 22
  90.   --  set c_right = the right of sprite 22
  91.   --  set c_left = c_right - 75
  92.   
  93.   -- calculate relative bar sizes and positions
  94.   set current_bottom = chartrect_bottom 
  95.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  96. * OBCfuel)
  97.   set xtop = chartrect_bottom - xxtop
  98.   set the rect of sprite 15 = rect(c_left,xtop,c_right,current_bottom)
  99.   set current_bottom = xtop
  100.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  101. * OBCair)
  102.   set xtop = current_bottom - xxtop
  103.   set the rect of sprite 16 = rect(c_left,xtop,c_right,current_bottom)
  104.   set current_bottom = xtop
  105.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  106. * OBCengine)
  107.   set xtop = current_bottom - xxtop
  108.   set the rect of sprite 17 = rect(c_left,xtop,c_right,current_bottom)
  109.   set current_bottom = xtop
  110.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  111. * OBCapu)
  112.   set xtop = current_bottom - xxtop
  113.   set the rect of sprite 18 = rect(c_left,xtop,c_right,current_bottom)
  114.   set current_bottom = xtop
  115.   set xxtop = (((1.0 * chartrect_bottom - chartrect_top) / totalmain)¼
  116. * OBCmisc)
  117.   set xtop = current_bottom - xxtop
  118.   set the rect of sprite 19 = rect(c_left,xtop,c_right,current_bottom)
  119.   set current_bottom = xtop
  120.   updatestage
  121. end
  122. on getmainvalues
  123.   global default_labor, default_fuel, currentplane
  124.   set default_labor = value(losemoney(the text of member "defaultLabor"))
  125.   set default_fuel = value(losemoney(the text of member "defaultFuel"))
  126.   getmainbars(currentplane, 0)
  127. end
  128.  
  129. on mainbars
  130.   global default_labor, default_fuel, currentplane
  131.   watchcursor()
  132.   set default_labor = value(losemoney(the text of member "defaultLabor"))
  133.   set default_fuel = value(losemoney(the text of member "defaultFuel"))
  134.   getmainbars(currentplane, 0)
  135.   drawmainbars
  136.   arrowcursor()
  137. end
  138. on compbars airplanename
  139.   global default_labor, default_fuel
  140.   watchcursor()
  141.   if ((airplanename = "No Competitor") or (length(airplanename)<4)) or ¼
  142. (airplanename = "NONE") then
  143.     set the text of member "disPlane" to "No Competitor"
  144.     set the text of member "achplanename" = " "
  145.     go to "Hourly costs"
  146.     updatestage
  147.   else
  148.     set the text of member "disPlane" to airplanename
  149.     set the text of member "achplanename" = airplanename
  150.     set outplane = airplanename
  151.     set default_labor = value(losemoney(the text of member "defaultLabor"))
  152.     set default_fuel = value(losemoney(the text of member "defaultFuel"))
  153.     getmainbars(outplane, 1)
  154.     drawmainbars
  155.     drawcompbars
  156.   end if
  157.   arrowcursor()
  158. end
  159.  
  160. -- losemoney
  161. -- remove $ from stringtoparse
  162.  
  163. on losemoney stringtoparse
  164.   set icx = offset("$", stringtoparse)
  165.   if icx = 0 then
  166.     nothing
  167.   else
  168.     delete char icx of stringtoparse
  169.   end if
  170.   set icx = offset(" ", stringtoparse)
  171.   if icx = 0 then
  172.     nothing
  173.   else
  174.     delete char icx of stringtoparse
  175.   end if
  176.   return stringtoparse
  177. end
  178.  
  179. -- fill data for bar graphs
  180. on getmainbars dataplanename, mainbarflag
  181.   global OBmisc, OBapu, OBengine, OBair, OBfuel
  182.   global OBCmisc, OBCapu, OBCengine, OBCair, OBCfuel, OBtotal, OBCtotal
  183.   global default_labor, default_fuel, currentplane
  184.   
  185.   set default_labor = value(losemoney(the text of field "defaultlabor"))
  186.   set default_fuel = value(losemoney(the text of field "defaultfuel"))
  187.   set ochours = the text of field "bar_hours"
  188.   set ocregion = the text of field "bar_region"
  189.   set notconk = false
  190.   set dp = the text of field "disPlane"
  191.   if ((length(dp)>4) and (dp<>"No Competitor")) then 
  192.     set notconk = TRUE
  193.     set the text of field "bar_hours" = "Conklin"
  194.     set ochours = "Conklin"
  195.   end if
  196.   
  197.   if (ochours = "Conklin") then
  198.     set qdHandle =DGQDOpen("Operating_CostVals_Conklin",dbHandle)
  199.   else
  200.     -- not the default hours entered in popup
  201.     set qdHandle =DGQDOpen("Operating_CostVals",dbHandle)
  202.     if DGQDsetParameterValue("Hours", ochours, qdhandle) = "#ERROR#" then 
  203.       put "p:"&&GetLastDGError()
  204.     end if
  205.   end if  
  206.   if qdHandle="#ERROR" then
  207.     alert "Error:"&&GetLastDGError()
  208.   end if
  209.   if DGQDsetParameterValue("Bomb plane", currentplane, qdhandle) = "#ERROR#" then 
  210.     put "p:"&&GetLastDGError()
  211.   end if
  212.   if DGQDsetParameterValue("Model", dataplanename, qdhandle) = "#ERROR#" then 
  213.     put "p:"&&GetLastDGError()
  214.   end if
  215.   
  216.   if DGQDsetParameterValue("Region Value", ocregion, qdhandle) = "#ERROR#" then 
  217.     put "p:"&&GetLastDGError()
  218.   end if
  219.   set rsHandle=DGQDCreateRS(qdHandle)
  220.   if rsHandle = "#ERROR#" then
  221.     alert "Bar DB Error"
  222.   else
  223.     -- put DGRSGetRecordCount(rsHandle)&&"counts"
  224.     -- get data
  225.     set landfees = DGRSGetFieldValuech("Landing Fees", rshandle)
  226.     set parkfees = DGRSGetFieldValuech("Parking Fees", rshandle)
  227.     set passserv = DGRSGetFieldValuech("Passengers Service", rshandle)
  228.     set tan = DGRSGetFieldValuech("Terminal Air Navigation", rshandle)
  229.     set ran = DGRSGetFieldValuech("Route Air Navigation", rshandle)
  230.     set crew = DGRSGetFieldValuech("Crew Expenses", rshandle)
  231.     set supplies = DGRSGetFieldValuech("Small Supplies and Catering", rshandle)
  232.     set smartparts = DGRSGetFieldValuech("Smart-Parts", rshandle)
  233.     set cMisc = landfees + parkfees + passserv + tan + ran + crew + supplies 
  234.     set cApu = DGRSGetFieldValuech("Apu", rshandle)
  235.     set englm = DGRSGetFieldValuech("Engin- LaborMultiplier", rshandle)
  236.     set avilm = DGRSGetFieldValuech("Avionics-LaborMultiplier", rshandle)
  237.     set airlm = DGRSGetFieldValuech("Airframe-LaborMulitplier", rshandle)
  238.     set engparts = DGRSGetFieldValuech("Engine-Parts", rshandle)
  239.     set thrustrev = DGRSGetFieldValuech("Thrust Reverser", rshandle)
  240.     set cEngine = float(englm * default_labor) + engparts + thrustrev
  241.     set cAir = smartparts + float(avilm*default_labor)+float(airlm*default_labor)
  242.     set burnrate = chgetfieldvalue("Fuel-burnRate", rshandle)
  243.     
  244.     -- put "air="&&cair"- smartparts="&&smartparts&&"- avilm="&&avilm&&"- airlm="&&airlm
  245.     
  246.     set cfuel = float(burnrate * Default_fuel)
  247.     set Oototal = cmisc + capu + cengine + cair + cfuel
  248.     if mainbarflag = 0 then   
  249.       -- main bar
  250.       set OBmisc = integer(cmisc)
  251.       set OBapu = integer(capu)
  252.       set OBengine = integer(cEngine)
  253.       set OBair = integer(cAir)
  254.       set OBfuel = integer(cFuel)
  255.       set OBtotal = integer(oototal)
  256.       set the text of field "aaplanename" = dataplanename
  257.       set the text of field "aabartotal" = "$" & string(oBtotal)
  258.       set the text of field "amisc" = "$" & string(obmisc)
  259.       set the text of field "aapu" = "$" & string(obapu)
  260.       set the text of field "aengine" = "$" & string(obengine)
  261.       set the text of field "aair" = "$" & string(obair)
  262.       set the text of field "afuel" = "$" & string(obfuel)
  263.     else
  264.       -- competitor bar
  265.       set OBCmisc = integer(cmisc)
  266.       set OBCapu = integer(capu)
  267.       set OBCengine = integer(cEngine)
  268.       set OBCair = integer(cAir)
  269.       set OBCfuel = integer(cFuel)
  270.       set OBCtotal = integer(oototal)
  271.       set the text of field "acplanename" = dataplanename
  272.       set the text of field "acbartotal" = "$" & string(obctotal)
  273.       set the text of field "cmisc" = "$" & string(obcmisc)
  274.       set the text of field "capu" = "$" & string(obcapu)
  275.       set the text of field "cengine" = "$" & string(obcengine)
  276.       set the text of field "cair" = "$" & string(obcair)
  277.       set the text of field "cfuel" = "$" & string(obcfuel)
  278.     end if  
  279.     if qdHandle > 0 then
  280.       if DGQDIsOpen(qdHandle) then 
  281.         DGQDClose(qdHandle)
  282.       end if 
  283.       set qdHandle = 0
  284.     end if  
  285.     if rsHandle > 0 then
  286.       if DGRSIsOpen(rsHandle) then 
  287.         DGRSClose(rsHandle)
  288.       end if 
  289.       set rsHandle = 0
  290.     end if  
  291.   end if
  292.   --  set rsHandle = 0
  293.   --  set qdHandle = 0
  294. end
  295.  
  296.  
  297. -- get field and error check
  298. on chgetfieldvalue parameterin, recordsethandle
  299.   set outch = DGRSGetFieldValue(parameterin,recordsethandle)
  300.   if outch = "#ERROR#" then 
  301.     put parameterin&&GetLastDGError()
  302.   end if 
  303.   --  put parameterin && "=" && outch
  304.   return outch
  305. end
  306.